<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
    <%@taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
    <%@taglib uri="http://www.springframework.org/tags" prefix="spring" %>
    <%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>

<style type="text/css">
.error{
	color: red;
}

.errorblock {
	color: #000;
	background-color: #ffEEEE;
	border: 3px solid #ff0000;
	padding: 8px;
	margin: 16px;
}
</style>

</head>
<body>

<form:form action="add.htm" method="post" commandName="student">
		<form:errors path="*" cssClass="errorblock" element="div" ></form:errors>
		<table width="100%">
			<tr>
				<td><form:label path="name"><spring:message code="label.name" /> </form:label></td>
				<td><form:input path="name"/> </td>
				<td><form:errors path="name" cssClass="error" /> </td>
			</tr>
			<tr>
				<td><form:label path="gender"><spring:message code="label.gender" /> </form:label></td>
				<td><form:radiobutton path="gender" value="0" />Male 
				<form:radiobutton path="gender" value="1" />Female</td>
				<td><form:errors path="gender" cssClass="error" /> </td>
			</tr>
			<tr>
				<td><form:label path="birthday"><spring:message code="label.birthday" /></form:label></td>
				<td>
				<form:input path="birthday" /> </td>
				<td><form:errors path="birthday" cssClass="error" /> </td>
			</tr>
			<tr>
				<td><form:label path="grade"><spring:message code="label.grade" /></form:label></td>
				<td><form:input path="grade"/> </td>
				<td><form:errors path="grade" cssClass="error" /> </td>
			</tr>
			<tr>
				<td><form:label path="school"><spring:message code="label.school" /></form:label></td>
				<td><form:select path="school" cssStyle="width:150px">
					<form:option value="0" label="-- Select one --"></form:option>
					<form:options items="${schools }" itemLabel="name" itemValue="id"/>
				</form:select> </td>
				<td><form:errors path="school" cssClass="error" /> </td>
			</tr>
			<tr>
				<td><form:label path="clazz"><spring:message code="label.clazz" /></form:label></td>
				<td><form:select path="clazz" cssStyle="width:150px">
					<form:option value="0" label="-- Select one --"></form:option>
					<form:options items="${clazzes }" itemLabel="name" itemValue="id"/>
				</form:select> </td>
				<td><form:errors path="clazz" cssClass="error" /> </td>
			</tr>
			<tr>
				<td ></td>
				<td><input type="submit" value="Add Student"> </td>
			</tr>
		</table>
	</form:form>
	<hr>
	<c:if test="${!empty studentList }">
		<table border="1">
			<tr>
				<th>Name</th>
				<th>Gender</th>
				<th>Birthday</th>
				<th>Grade</th>
				<th>School</th>
				<th>Class</th>
				<th>&nbsp;</th>
			</tr>
			<c:forEach items="${studentList }" var="student">
				<tr>
					<td>${student.name }</td>
					<td>${student.gender }</td>
					<td>${student.birthday }</td>
					<td>${student.grade }</td>
					<td>${student.school.name }</td>
					<td>${student.clazz.name }</td>
					<td><a href="/delete/${student.id }">delete</a> </td>
				</tr>
			</c:forEach>
		</table>
	</c:if>
</body>
</html>
